package org.example.controller;


import jakarta.annotation.Resource;
import org.example.po.Business;
import org.example.po.CommonResult;
import org.example.service.BusinessService;
import org.example.service.FoodFeign;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RefreshScope
@RestController
@RequestMapping("/Business")
public class BusinessController {
    @Resource
    private BusinessService businessService;
    @Resource
    private FoodFeign foodFeign;


    @GetMapping("/OrderTypeId/{orderTypeId}")
    public CommonResult<List> listBusinessByOrderTypeId(@PathVariable("orderTypeId") Integer orderTypeId) throws Exception {
        return new CommonResult<List>(200, "success",
                businessService.listBusinessByOrderTypeId(orderTypeId));
    }

    @GetMapping("/BusinessId/{businessId}")
    public CommonResult<Business> getBusinessById(@PathVariable("businessId") Integer businessId) throws Exception {

             Business business  = businessService.getBusinessById(businessId);

          CommonResult<List> result = foodFeign.listFood(businessId);
        if (result.getCode() == 200) {
            business.setFoodList(result.getResult());
            return new CommonResult(200, "success", business);
        }else {
            String mess="服务器出错啦";
            Map map=new HashMap();
            map.put("business",business);
            map.put("food",mess);
            return new CommonResult(200, "没有找到菜",map);
        }

    }
    }

